<?php
namespace app\admin\model;
use think\Model;
/**
* 
*/
class Ordered extends model{
	function fuids($andicap,$bet,$cloums,$id,$datatime,$uid){
			$res = db('ordered')->alias('oed')->where(['oed.datatime'=>$datatime,"oed.user_id"=>$id])->join('orders os','oed.id=os.order_id','left')->where('os.bets','<',50)->where(['os.andicap'=>$andicap,'os.bet'=>$bet,'os.colums'=>$cloums])->join("occupy op",'oed.user_id=op.user_id')->select();
			foreach ($res as $key => $v) {
				$sb = db('buhuo')->where(['datatime'=>$v['datatime'],'bet'=>$v['bet']])->where(['colums'=>$v['colums'],'bets'=>$v['bets']])->where('topuser',$uid)->sum('price');
				$bh = db('buhuo')->where(['datatime'=>$v['datatime'],'bet'=>$v['bet']])->where(['colums'=>$v['colums'],'bets'=>$v['bets']])->where('user_id',$uid)->sum('price');
				$res[$key]['bh'] = $bh;
				$res[$key]['sb'] = $sb;
			}
			return $res;
	}
	function finrede($andicap,$bet,$id,$datatime,$uid){
		$res = db('ordered')->alias('oed')->where(['oed.datatime'=>$datatime,"oed.user_id"=>$id])->join('orders os','oed.id=os.order_id','left')->where(['os.bet'=>$bet])->order('os.price','desc')->limit(100)->select();
			foreach ($res as $key => $v) {
				$sb = db('buhuo')->where(['datatime'=>$v['datatime'],'bet'=>$v['bet']])->where(['colums'=>$v['colums'],'bets'=>$v['bets']])->where('topuser',$uid)->sum('price');
				$bh = db('buhuo')->where(['datatime'=>$v['datatime'],'bet'=>$v['bet']])->where(['colums'=>$v['colums'],'bets'=>$v['bets']])->where('user_id',$uid)->sum('price');
				$res[$key]['bh'] = $bh;
				$res[$key]['sb'] = $sb;
			}
			return $res;
	}
	function findall(){
		$res = db('ordered')->select();
		return $res;
	}
	function findallqishu(){
		$ordered = db('ordered')->select();
		foreach ($ordered as $key => $value) {
			$arr[] = $value['datatime'];
		};
		$arr1=array_unique($arr);
		return $arr1;
	}
	function findqishu($qishu){
		$res = db('ordered')->where('datatime',$qishu)->select();
		return $res;
	}
	function findid($id){
		$res = $this->where('id',$id)->count();
		return $res;
	}
	function findoid1($id,$stime,$etime){
		$res = db('ordered')->where('times','>',$stime)->where('times','<',$etime)->where('id',$id)->select();
		return $res;
	}
	function findoid1qishu($id,$stime,$etime,$qishu){
		$res = db('ordered')->where('times','>',$stime)->where('times','<',$etime)->where('id',$id)->where('datatime',$qishu)->select();
		return $res;
	}
	function findid1($id){
		$res = db('ordered')->where('id',$id)->select();
		return $res;
	}
	function takedanhao($danhao){
		$quanbiao = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('o1.times+o1.id',$danhao)->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $quanbiao;
	}
	function findshijiancuo($shijiancuo){
		$res = db('ordered')->where('times',$shijiancuo)->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function finduserid($userid,$stime,$etime){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('o1.user_id',$userid )->where('times','>',$stime)->where('times','<',$etime)->where('o2.andicap',1)->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function finduseridqishu($userid,$stime,$etime,$qishu){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('o1.user_id',$userid )->where('times','>',$stime)->where('times','<',$etime)->where('o2.andicap',1)->where('o1.datatime',$qishu)->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function finduseridzhonglei($userid,$stime,$etime,$bet,$colums){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('o1.user_id',$userid )->where('times','>',$stime)->where('times','<',$etime)->where('o2.andicap',1)->where('o2.bet',$bet)->where('o2.colums',$colums)->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function finduseridqishuzhonglei($userid,$stime,$etime,$qishu,$bet,$colums){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('o1.user_id',$userid )->where('times','>',$stime)->where('times','<',$etime)->where('o2.andicap',1)->where('o1.datatime',$qishu)->where('o2.bet',$bet)->where('o2.colums',$colums)->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function finduseridzhongleibets($userid,$stime,$etime,$qishu,$bet,$colums,$bets){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('o1.user_id',$userid )->where('times','>',$stime)->where('times','<',$etime)->where('o2.andicap',1)->where('o1.datatime',$qishu)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('bets',$bets)->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function finduseridqishuzhongleibets($userid,$stime,$etime,$qishu,$bet,$colums,$bets){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('o1.user_id',$userid )->where('times','>',$stime)->where('times','<',$etime)->where('o2.andicap',1)->where('o1.datatime',$qishu)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('bets',$bets)->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function findandicap($andicap,$stime,$etime,$uid){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('times','>',$stime)->where('times','<',$etime)->where('o2.andicap',$andicap)->where('o1.user_id',$uid )->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function findandicaps($stime,$etime,$uid){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('times','>',$stime)->where('times','<',$etime)->where('o1.user_id',$uid )->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function findandicapqishu($andicap,$stime,$etime,$qishu,$uid){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('times','>',$stime)->where('times','<',$etime)->where('o2.andicap',$andicap)->where('o1.datatime',$qishu)->where('o1.user_id',$uid )->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function findandicapqishuzhonglei($andicap,$stime,$etime,$qishu,$bet,$colums,$uid){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('times','>',$stime)->where('times','<',$etime)->where('o2.andicap',$andicap)->where('o1.datatime',$qishu)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('o1.user_id',$uid )->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function findandicapzhonglei($andicap,$stime,$etime,$bet,$colums,$uid){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('times','>',$stime)->where('times','<',$etime)->where('o2.andicap',$andicap)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('o1.user_id',$uid )->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function findandicapqishuzhongleibets($andicap,$stime,$etime,$qishu,$bet,$colums,$bets,$uid){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('times','>',$stime)->where('times','<',$etime)->where('o2.andicap',$andicap)->where('o1.datatime',$qishu)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('bets',$bets)->where('o1.user_id',$uid )->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function findandicapzhongleibets($andicap,$stime,$etime,$bet,$colums,$bets,$uid){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('times','>',$stime)->where('times','<',$etime)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('bets',$bets)->where('o1.user_id',$uid )->where('o2.andicap',$andicap)->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	function finddatatime($qishu){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.username,u.moneys,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o2.*,o1.price as zongprice')->where('o1.datatime',$qishu)->where('o1.jiesuan',0)->where('o2.zhongjiang',0)->select();
		foreach ($res as $k1 => $v1) {
                            $water = model('occupy')->tsinser($v1['andicap'],$v1['bet'],$v1['colums'],$v1['bets'],$v1['uid']);
                            $conter = inserpankous($v1['bet'],$v1['colums'],$v1['bets'],$v1['rname']);
                            $res[$k1]['conter'] = $conter;
                            $res[$k1]['water'] = $water;
                            if($res[$k1]['zhongjiang']==1){
                            	$res[$k1]['res'] = "+".$res[$k1]['rate']*$res[$k1]['price'];
                            }else{$res[$k1]['res'] = "-".$res[$k1]['price'];}
                        }
		return $res;
	}
	//这个是即时注单
	function findjishi($andicap,$bet,$colums,$bets,$uid,$qishu){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('returnwater t','o1.user_id=t.uid','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,t.*,t.id as tid,o1.*,o2.*,o1.price as zongprice')->where('o2.andicap',$andicap)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('o1.user_id',$uid)->where('o2.bets',$bets)->where('o1.datatime',$qishu)->order('o2.bets ')->select();
		return $res;
	}//这个是即时注单
	function findzheng1te($andicap,$bet,$colums,$uid,$qishu){
		$res1 = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('returnwater t','o1.user_id=t.uid','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,t.*,t.id as tid,o1.*,o2.*,o1.price as zongprice')->where('o2.andicap',$andicap)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('o1.user_id',$uid)->where('o2.bets','>=',1)->where('o2.bets','<=',9)->where('o1.datatime',$qishu)->order('o2.bets ')->select();
	}//这个是即时注单正1特
	function findzheng2te($andicap,$bet,$colums,$uid,$qishu){
		$res1 = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('returnwater t','o1.user_id=t.uid','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,t.*,t.id as tid,o1.*,o2.*,o1.price as zongprice')->where('o2.andicap',$andicap)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('o1.user_id',$uid)->where('o2.bets','>=',10)->where('o2.bets','<=',18)->where('o1.datatime',$qishu)->order('o2.bets ')->select();
	}//这个是即时注单正2特
	function findzheng3te($andicap,$bet,$colums,$uid,$qishu){
		$res1 = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('returnwater t','o1.user_id=t.uid','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,t.*,t.id as tid,o1.*,o2.*,o1.price as zongprice')->where('o2.andicap',$andicap)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('o1.user_id',$uid)->where('o2.bets','>=',19)->where('o2.bets','<=',27)->where('o1.datatime',$qishu)->order('o2.bets ')->select();
	}//这个是即时注单正3特
	function findzheng4te($andicap,$bet,$colums,$uid,$qishu){
		$res1 = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('returnwater t','o1.user_id=t.uid','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,t.*,t.id as tid,o1.*,o2.*,o1.price as zongprice')->where('o2.andicap',$andicap)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('o1.user_id',$uid)->where('o2.bets','>=',28)->where('o2.bets','<=',36)->where('o1.datatime',$qishu)->order('o2.bets ')->select();
	}//这个是即时注单正4特
	function findzheng5te($andicap,$bet,$colums,$uid,$qishu){
		$res1 = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('returnwater t','o1.user_id=t.uid','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,t.*,t.id as tid,o1.*,o2.*,o1.price as zongprice')->where('o2.andicap',$andicap)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('o1.user_id',$uid)->where('o2.bets','>=',37)->where('o2.bets','<=',45)->where('o1.datatime',$qishu)->order('o2.bets ')->select();
	}//这个是即时注单正5特
	function findzheng6te($andicap,$bet,$colums,$uid,$qishu){
		$res1 = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('returnwater t','o1.user_id=t.uid','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,t.*,t.id as tid,o1.*,o2.*,o1.price as zongprice')->where('o2.andicap',$andicap)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('o1.user_id',$uid)->where('o2.bets','>=',46)->where('o2.bets','<=',54)->where('o1.datatime',$qishu)->order('o2.bets ')->select();
	}//这个是即时注单正6特
	function findjishizonge($andicap,$bet,$colums,$uid,$qishu){
		// echo $andicap."+".$bet."+".$colums."+".$uid."+".$qishu;
		// exit();
		// $res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,o1.*,o2.*,o1.price as zongprice')->where('o2.andicap',$andicap)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('o1.user_id',$uid)->where('o1.datatime',$qishu)->order('o2.bets ')->select();
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('user u','o2.uid=u.id','LEFT')->where('o2.andicap',$andicap)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('o2.uid',$uid)->where('o1.datatime',$qishu)->select();
		return $res;
	}//这个是即时注单里面上面那个“特码”
	function findbuho($andicap,$bet,$colums,$uid,$qishu){
		$res = db('ordered')->alias('o1')->join('orders o2','o1.id=o2.order_id','LEFT')->join('returnwater t','o1.user_id=t.uid','LEFT')->join('buhuo b','o2.uid=b.user_id and o2.bet=b.bet and o2.bets=b.bets and o2.colums=b.colums','LEFT')->join('rate r','o2.bet=r.bet and o2.bets=r.bets and o2.colums=r.colums','LEFT')->join('user u','o2.uid=u.id','LEFT')->field('u.name,u.upoccupy as uupoccupy,r.name as rname,b.*,b.id as bid,b.topuser as btopuser,b.andicap as bandicap,b.bet as bbet,b.colums as bcolums,b.bets as bbets,b.price as bprice,t.*,t.id as tid,o1.*,o2.*,o1.price as zongprice')->where('o2.andicap',$andicap)->where('o2.bet',$bet)->where('o2.colums',$colums)->where('o1.user_id',$uid)->where('o1.datatime',$qishu)->order('o2.bets ')->select();
		return $res;
	}//查下级补货

}